package com.chao.order.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chao.order.client.StorgeFeignClient;
import com.chao.order.entity.OrderInfo;
import com.chao.order.mapper.OrderInfoMapper;
import com.chao.order.service.OrderInfoService;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.ExceptionHandler;

import java.math.BigDecimal;

/**
 * @author : Rookie
 * @description :
 * @date : 2022/9/18
 */
@Service
public class OrderInfoServiceImpl extends ServiceImpl<OrderInfoMapper, OrderInfo> implements OrderInfoService {

    @Autowired
    private StorgeFeignClient storgeFeignClient;

    @Override
    @GlobalTransactional
    public OrderInfo createOrder(String productId) {
        //创建订单
        OrderInfo orderInfo = new OrderInfo();
        orderInfo.setProductId("861023792").setUserId("fwc").setCount(5).setPrice(BigDecimal.TEN)
                .setStatus(0);

        //库存减除
        storgeFeignClient.deductStorge(orderInfo.getProductId(),orderInfo.getCount());
        int i = 10/0;
        return orderInfo.setStatus(1);
    }
}
